﻿Public Class clsWorkshopCurrent

    Public Function SaveData(workshop As String, current_section As String, support_model As String, b_pgd_sys_id As String, plan_quantity As String) As Integer
        Dim int_count As Integer = CInt(plan_quantity)
        Dim szSql As String
        Dim rtn As Integer
        szSql = String.Empty
        szSql &= "SELECT * FROM sf.b_workshop_current WHERE factory_id = ? and workshop = ? and current_section = ? "
        Dim dtxj As DataTable = DBacs.ExecuteSql(szSql, -1, "TS", workshop, current_section)
        If dtxj.Rows.Count = 0 Then
            szSql = String.Empty
            szSql &= "INSERT INTO sf.b_workshop_current( factory_id, workshop,current_section, b_pgd_sys_id, support_model,plan_quantity, update_time) "
            szSql &= "VALUES ( ? , ? , ? , ? ,? , ? ,(SELECT CURRENT_TIMESTAMP(6))); "
            rtn = DBacs.ExecuteUpdateSql(szSql, -1, "TS", workshop, current_section, b_pgd_sys_id, support_model, int_count)
        Else
            szSql = String.Empty
            szSql &= "UPDATE sf.b_workshop_current SET b_pgd_sys_id = ?, support_model = ?, plan_quantity = ?,update_time = (SELECT CURRENT_TIMESTAMP(6)) "
            szSql &= "WHERE factory_id = ? and workshop = ? and current_section = ? "
            rtn = DBacs.ExecuteUpdateSql(szSql, -1, b_pgd_sys_id, support_model, int_count, "TS", workshop, current_section)
        End If
        Return rtn
    End Function

    Public Function GetListByWorkShopIdAndCurrentSection(workshop_id As String, current_section As String) As DataTable
        Dim szSql As String = "SELECT a.*,b.oper_count FROM sf.b_workshop_current a "
        szSql &= " left join sf.b_gt_pgd_mes b on a.b_pgd_sys_id = b.sys_id"
        szSql &= " where a.workshop = ? and a.current_section = ?"
        Return DBacs.ExecuteSql(szSql, -1, workshop_id, current_section)
    End Function

    Public Function getListByWorkshop(workshop As String) As DataTable
        Dim szSql As String = ""
        szSql &= "select a.*,b.flb_type,b.gjb_type from sf.b_workshop_current a left join sf.t_prod_spec b on a.support_model = b.prod_spec_id"
        szSql &= " where a.workshop = ? "
        Return DBacs.ExecuteSql(szSql, -1, workshop)
    End Function

    Public Function updateDataClear(workshop As String, current_section As String) As Integer
        Dim szSql As String = "UPDATE sf.b_workshop_current SET b_pgd_sys_id = ?, support_model = ?, update_time = (SELECT CURRENT_TIMESTAMP(6)) ,plan_quantity=?,finished_quantity=?"
        szSql &= "WHERE factory_id = ? and workshop = ? and current_section = ? "
        Return DBacs.ExecuteUpdateSql(szSql, -1, 0, DBNull.Value, 0, 0, "TS", workshop, current_section)
    End Function
End Class
